<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'hiringCompany-form',
    'enableClientValidation' => true,    
    ));
?>
<table class="form" style="width: 100%">
	<tr>
		<td class="label required"><?php echo $form->labelEx($model, 'code'); ?></td>
		<td class="input">
            <?php            
                echo $form->textField($model, 'code', array('style' => 'width:230px'));
            ?>
            <?php echo $form->error($model, 'code'); ?>
        </td>
	</tr>
	<tr>
		<td class="label required"><?php echo $form->labelEx($model, 'name'); ?></td>
		<td class="input">
            <?php            
                echo $form->textField($model, 'name', array('style' => 'width:230px'));
            ?>
            <?php echo $form->error($model, 'name'); ?>
        </td>
	</tr>
	<tr>
		<td class="label"><?php echo $form->labelEx($model, 'director'); ?></td>
		<td class="input">
            <?php            
                echo $form->textField($model, 'director', array('style' => 'width:230px'));
            ?>
            <?php echo $form->error($model, 'director'); ?>
        </td>
	</tr>
	<tr>
		<td class="label"><?php echo $form->labelEx($model, 'address'); ?></td>
		<td class="input">
            <?php            
                echo $form->textField($model, 'address', array('style' => 'width:230px'));
            ?>
            <?php echo $form->error($model, 'address'); ?>
        </td>
	</tr>
	<tr>
		<td class="label required"><?php echo $form->labelEx($model, 'phone_number'); ?></td>
		<td class="input">            
            <?php
            echo $form->textField($model, 'phone_number', array('style' => 'width:230px'));
            echo $form->error($model, 'phone_number');
            ?>
        </td>
	</tr>
	<tr>
		<td class="label required"><?php echo $form->labelEx($model, 'salary'); ?></td>
		<td class="input">            
            <?php
            echo $form->textField($model, 'salary', array('style' => 'width:230px'));
            echo $form->error($model, 'salary');
            ?>
        </td>
	</tr>
	<tr>
		<td class="label required"><?php echo $form->labelEx($model, 'introducing_fee'); ?></td>
		<td class="input">            
            <?php
            echo $form->textField($model, 'introducing_fee', array('style' => 'width:230px'));
            echo $form->error($model, 'introducing_fee');
            ?>
        </td>
	</tr>
	<tr>
		<td class="label required"><?php echo $form->labelEx($model, 'union_id'); ?></td>
		<td class="input">            
            <?php
            echo Html::customDropDownList($model, 'union_id', Union::model()->findAll(), 'id', 'name', array('allowance', 'management_fee'), t('DROPDOWN_FIRST_ITEM_UNION', 'hiringCompany'));
            echo Html::buttonAddPartial('button_add_new_union');                       	           	
            echo $form->error($model, 'union_id');            
            ?>
        </td>
	</tr>
	<tr>
		<td class="label required"><?php echo $form->labelEx($model, 'first_month_allowance'); ?></td>
		<td class="input">            
            <?php
            echo $form->textField($model, 'first_month_allowance', array('id' => 'textfield_union_allowance', 'style' => 'width:230px'));
            echo $form->error($model, 'first_month_allowance');
            ?>
        </td>
	</tr>
	<tr>
		<td class="label required"><?php echo $form->labelEx($model, 'management_fee'); ?></td>
		<td class="input">            
            <?php
            echo $form->textField($model, 'management_fee', array('id' => 'textfield_union_management_fee', 'style' => 'width:230px'));
            echo $form->error($model, 'management_fee');
            ?>
        </td>
	</tr>
	<tr>
		<td colspan="2" class="cbutton">
<?php echo Html::buttonConfirm(t('BTN_SAVE'), 'statusConfirmed'); ?>
<?php echo Html::buttonConfirm(t('BTN_CANCEL'), 'statusCanceled', 'cancel'); ?>
        </td>
	</tr>
</table>
<?php $this->endWidget(); ?>
<script type="text/javascript">
	LGCMS.addTooltip();
	$('#HiringCompany_union_id').change(function(){			
		if($(this).find('option:selected').attr('data') != undefined)
		{
			var data = $(this).find('option:selected').attr('data').split('||');			
			$('#textfield_union_allowance').val(data[0]);
			$('#textfield_union_management_fee').val(data[1]);
		}
		else
		{			
			$('#textfield_union_allowance').val('');
			$('#textfield_union_management_fee').val('');
		}
	});	 
	$("#button_add_new_union").click(function() {
		popupCreateUnion = $('#popupCreateUnion');
		popupCreateUnion.html( '<div class="ajax-loader" ></div>');
		popupCreateUnion.dialog({			
			modal: true,
			width: 500,
			height: 400,
			title: 'Thêm mới Nghiệp đoàn'
		});
		$.ajax({
            url: '<?php echo url('/union/create');?>',
            type: "post",
            dataType: "json",
            cache: false,
            success: function(response){            		
            	popupCreateUnion.html(response.content);	            		           		               
            }
        });
    });   
</script>